<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flask 文件上传演示</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card shadow">
                    <div class="card-header bg-primary text-white">
                        <h3 class="mb-0">
                            <i class="fas fa-cloud-upload-alt me-2"></i>
                            文件上传演示
                        </h3>
                    </div>
                    <div class="card-body">
                        <!-- 消息提示 -->
                        {% with messages = get_flashed_messages() %}
                            {% if messages %}
                                {% for message in messages %}
                                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                                        <i class="fas fa-check-circle me-2"></i>
                                        {{ message }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        {% endwith %}

                        <!-- 上传表单 -->
                        <form action="{{ url_for('upload_file') }}" method="post" enctype="multipart/form-data">
                            <div class="mb-3">
                                <label for="file" class="form-label">
                                    <i class="fas fa-file-upload me-1"></i>
                                    选择要上传的文件：
                                </label>
                                <input type="file" class="form-control" id="file" name="file" required>
                                <div class="form-text">支持任意类型的文件上传</div>
                            </div>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-upload me-1"></i>
                                上传文件
                            </button>
                        </form>

                        <!-- 已上传文件列表 -->
                        {% if files %}
                            <hr class="my-4">
                            <h5>
                                <i class="fas fa-list me-1"></i>
                                已上传的文件
                            </h5>
                            <div class="list-group">
                                {% for file in files %}
                                    <div class="list-group-item d-flex justify-content-between align-items-center">
                                        <span>
                                            <i class="fas fa-file me-2"></i>
                                            {{ file }}
                                        </span>
                                        <span class="badge bg-secondary rounded-pill">
                                            {{ (uploads_folder + '/' + file) | filesizeformat if (uploads_folder + '/' + file) is file else '未知大小' }}
                                        </span>
                                    </div>
                                {% endfor %}
                            </div>
                        {% else %}
                            <hr class="my-4">
                            <div class="text-center text-muted">
                                <i class="fas fa-folder-open fa-3x mb-3"></i>
                                <p>暂无已上传的文件</p>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
</body>
</html>